<template>
  <avue-crud
    :data="data"
    :option="option"
    :page.sync="page"
    @on-load="rowLoad"
    @search-change="searchChange"
    @refresh-change="rowLoad(page)"
    @row-update="rowUpdate"
    @row-del="rowDel"
    @row-save="rowSave"
    @size-change="sizeChange"
    @current-change="currentChange"
  >
  </avue-crud>
</template>

<script>
import avue from "@/mixins/avue.js";
import { SE, NY } from "@/common/constants.js";
import {
  config_page,
  config_add,
  config_edit,
  config_delete,
} from "@/api/core/system";

export default {
  mixins: [avue],
  props: {
    category: {
      type: String,
      default: "app",
    },
  },
  data() {
    return {
      itemDrawer: false,
      itemData: [],
      menuProps: {
        label: "name",
      },
      menuDataRole: [],
      curRole: {},
      data: [],
      option: {
        dialogDirection: "rtl",
        dialogType: "drawer",
        column: [
          // {
          //   label: "参数分类",
          //   prop: "code",
          //   align: "left",
          //   search: true,
          // },
          {
            label: "参数编码",
            prop: "code",
            align: "left",
            search: true,
          },
          {
            label: "参数名称",
            prop: "name",
            align: "left",
            search: true,
          },
          {
            label: "参数值",
            prop: "value",
            align: "left",
          },
          {
            label: "备注",
            prop: "remark",
          },
          {
            label: "状态",
            prop: "status",
            type: "radio",
            dicData: SE,
            value: "1",
            search: true,
          },
          {
            label: "排序",
            prop: "sort",
          },
        ],
      },
    };
  },
  methods: {
    setDictItem(row) {
      this.$refs.dictItem.dictDetail(row.id);
    },
    rowLoad() {
      config_page({ ...this.params, category: this.category }).then((res) => {
        this.data = this.$s.res(res).records;
      });
    },
    rowSave(row, loading, done) {
      row.category = this.category;
      config_add(row).then((res) => {
        this.$s.suc(res);
        this.rowLoad(this.params);
        done();
        loading();
      });
    },
    rowUpdate(row, index, done, loading) {
      config_edit(row).then((res) => {
        this.$s.suc(res);
        this.rowLoad(this.params);
        done();
        loading();
      });
    },
    rowDel(row, index) {
      this.$confirm("确定数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        config_delete({ ids: row.id }).then((res) => {
          this.$s.suc(res);
          this.rowLoad(this.params);
        });
      });
    },
  },
  mounted() {},
};
</script>
